package Model;

import Helper.Helper;

import java.util.ArrayList;

public class Vendor extends Record{
    private String password;
    private boolean status;

    public Vendor(){
        status = false;
    }

    public Vendor(String name, String password){
        status = false;

        this.name = name;
        this.password = password;
    }

    public boolean getStatus(){
        return status;
    }

    String getPassword(){
        return password;
    }

    public void setStatus(String name, String password){
        if( this.name.equals(name) && this.password.equals(password) ){
            this.status = true;
        }
    }

    public ArrayList<Product> listProducts(){
        ProductM productM = new ProductM();

        return productM.all();
    }

    public ArrayList<Product> searchProducts(String name){
        ProductM productM = new ProductM();

        return productM.find(name);
    }

    public boolean addProduct(String name, float price, int amount, int status){
        if( getStatus() ){
            ProductM productM = new ProductM();

            Product p = new Product(name, price, amount, Helper.getSession(0), status);

            return productM.add(p);
        }else{
            return false;
        }
    }

    public boolean removeProduct(int id){
        ProductM productM = new ProductM();

        return productM.remove(id);
    }

    public boolean editProduct(int id, String name, float price, int amount, int status){
        if( getStatus() ){
            ProductM productM = new ProductM();

            Product p = new Product(name, price, amount, "", status);
            // 由于此处卖家id根本不会被用到， 故瞎几把写
            p.id = id;

            return productM.edit(p);
        }else{
            return false;
        }
    }
}
